Allow specifying a custom output directory
authorAlex Crichton <alex@alexcrichton.com>
Thu, 28 May 2015 22:39:20 +0000 (15:39 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 28 May 2015 22:51:02 +0000 (15:51 -0700)
commit014765f788ca1c2476936835ca32cc2746f99b42
tree7bba52efd9a046652b853c1fe97d6a3176931e38
parent655c40be25fb37c73f10168d4d39d3af6f3047ce
Allow specifying a custom output directory

This commit adds support to allow specifying a custom output directory to Cargo.
First, the `build.target-dir` configuration key is checked, and failing that the
`CARGO_TARGET_DIR` environment variable is checked, and failing that the root
package's directory joined with the directory name "target" is used.

There are a few caveats to switching target directories, however:

* If the target directory is in the current source tree, and the folder name is
  not called "target", then Cargo may walk the output directory when determining
  whether a tree is fresh.
* If the target directory is not called "target", then Cargo may look inside it
  currently for `Cargo.toml` files to learn about local packages.
* Concurrent usage of Cargo will still result in badness (#354), and this is now
  exascerbated because many Cargo projects can share the same output directory.
* The top-level crate is not cached for future compilations, so if a crate is
  built into directory `foo` and then that crate is later used as a dependency,
  it will be recompiled.

The naming limitations can be overcome in time, but for now it greatly
simplifies the crawling routines and shouldn't have much of a negative impact
other than some Cargo runtimes (which can in turn be negated by following the
"target" name convention).

Closes #482
src/cargo/core/manifest.rs
src/cargo/core/package.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_doc.rs
src/cargo/ops/cargo_package.rs
src/cargo/ops/cargo_rustc/layout.rs
src/cargo/ops/cargo_rustc/mod.rs
src/cargo/util/config.rs
src/cargo/util/toml.rs
src/doc/config.md
tests/test_cargo_compile.rs